﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;
using System.Web;

namespace HMS.Data
{
    public class PatientService
    {
        public int SavePatientDetails(Patient patient)
        {
            using (var dt = new HMSEntities())
            {
                try
                {
                    Patient patientObj = dt.Patients.Find(patient.Patient_id);
                    patientObj.Patient_Name = patient.Patient_Name;
                    patientObj.Patient_Email = patient.Patient_Email;
                    patientObj.Patient_Phone = patient.Patient_Phone;
                    patientObj.Patient_Gender = patient.Patient_Gender;
                    patientObj.Patient_DOB = patient.Patient_DOB;
                    return dt.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
                catch (Exception ex)
                {
                    throw new Exception();
                }
            }
        }
    }
}
